#ifndef XM_POLLER_HH
#define XM_POLLER_HH

#include <vector>
#include <unordered_map>

#include "XM_noncopyable.hh"
#include "XM_Timestamp.hh"
#include "pch.hh"

XM_NAMESPACE_BEGIN

struct Channel;
struct EvLoop;

struct Poller
{
    using ChannelList = std::vector<Channel*>;

    Poller(EvLoop* lop);
    virtual ~Poller() = default;

    virtual XM_Timestamp poll(int timeoutMs, ChannelList* activeChannels) = 0;
    virtual void updateChannel(Channel* channel) = 0;
    virtual void removeChannel(Channel* channel) = 0;

    bool hasChannel(Channel* channel) const;

    static Poller* newDefaultPoller(EvLoop* lop);

protected:
    using ChannelMap = std::unordered_map<int, Channel*>;
    ChannelMap channels__;

private:
    EvLoop* ownerLoop__;
};

XM_NAMESPACE_END

#endif // header file protect